package adv331;

import java.io.Serializable;
import java.util.Objects;

public class Student implements Comparable<Student> , Serializable {
    private String name;
    private int age;
    private Sex sex;
    //不允许序列化这个idcar
    private transient String idcard;

    public Student() {
    }

    public Student(String name, int age, Sex sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    public Student(String name, int age, Sex sex, String idcard) {
        this.name = name;
        this.age = age;
        this.sex = sex;
        this.idcard = idcard;
    }
    private Student(int age,String name,  Sex sex, String idcard) {
        this.name = name;
        this.age = age;
        this.sex = sex;
        this.idcard = idcard;
    }

    public String getIdcard() {
        return idcard;
    }

    public void setIdcard(String idcard) {
        this.idcard = idcard;
    }
//    @Override
//    public int hashCode() {
//        return this.name.hashCode();
//    }
//
//    @Override
//    public boolean equals(Object obj) {
//        if (obj instanceof Student) {
//            Student stu = (Student) obj;
//            return (this.name.equals(stu.name));
//        }
//        return false;
//    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(name, student.name);
    }
    @Override
    public int hashCode() {
        return Objects.hash(name);
    }

//    @Override
//    public boolean equals(Object o) {
//        if (this == o) return true;
//        if (o == null || getClass() != o.getClass()) return false;
//        Student student = (Student) o;
//        return age == student.age &&
//                Objects.equals(name, student.name) &&
//                sex == student.sex;
//    }
//
//    @Override
//    public int hashCode() {
//        return Objects.hash(name, age, sex);
//    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex=" + sex +
                ", 身份证=" + this.idcard +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Sex getSex() {
        return sex;
    }

    public void setSex(Sex sex) {
        this.sex = sex;
    }

    private boolean incr(int a){
        if(a>10||a<=0)
            return false;
        this.age+=a;
        return true;
    }
    @Override
    public int compareTo(Student o) {
        //return this.name.compareTo(o.name);
          return this.age-o.age;
        // return o.age-this.age;
    }
}
